<template>
  <div class="app-container teacher-form-container">
    <div v-if="opt != 'add'">
      <el-descriptions title="">
        <el-descriptions-item label="平台名称">
          <el-tag size="medium" style="margin-top: -5px">{{ index }}</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="平台信息" name="first">
        <el-form :model="form" ref="form" :rules="rules" label-width="100px">
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="平台名称" prop="enterpriseName">
                <el-input
                  v-model="form.enterpriseName"
                  placeholder="请输入平台名称"
                  maxlength="50"
                  :disabled="opt == 'details'"
                  @blur="validateEnterpriseName"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="行政区域" prop="administrativeArea">
                <TreeSelect
                  v-model="form.administrativeArea"
                  :options="options"
                  :show-count="true"
                  :normalizer="normalizer"
                  :load-options="loadOptions"
                  @input="areaChange"
                  placeholder="请选择行政区域"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="平台性质" prop="enterpriseNature">
                <el-select
                  v-model="form.enterpriseNature"
                  style="width: 100%"
                  placeholder="请选择平台性质"
                >
                  <el-option
                    v-for="dict in dict.type.enterprise_nature"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="公司编号" prop="enterpriseNo">
                <el-input v-model="form.enterpriseNo" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="注册资金" prop="registeredCapital">
                <el-input
                  v-model="form.registeredCapital"
                  placeholder="请输入注册资金"
                  maxlength="50"
                >
                  <template #append>万元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="平台来源" prop="enterpriseSource">
                <el-select
                  v-model="form.enterpriseSource"
                  style="width: 100%"
                  placeholder="请选择平台来源"
                >
                  <el-option
                    v-for="dict in dict.type.enterprise_source"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="所属行业" prop="industry">
                <TreeSelect
                  v-model="form.industry"
                  :options="industryOptions"
                  :normalizer="industryNormalizer"
                  :load-options="loadIndustryOptions"
                  :searchable="true"
                  :clearable="true"
                  placeholder="请选择所属行业"
                  style="width: 100%"
                  @input="handleIndustryChange"
                />
              </el-form-item>
            </el-col>
            <el-col :span="16" style="height: 55px">
              <el-form-item label="详细地址" prop="enterpriseAddress">
                <el-input
                  v-model="form.enterpriseAddress"
                  placeholder="请输入详细地址"
                  maxlength="400"
                  show-word-limit
                  :title="form.enterpriseAddress"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="法人代表" prop="legalRepresentative">
                <el-input
                  v-model="form.legalRepresentative"
                  placeholder="请输入法人代表"
                  maxlength="50"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="成立日期" prop="establishmentDate">
                <el-date-picker
                  clearable
                  style="width: 100%"
                  v-model="form.establishmentDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择成立日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="联系人" prop="contacts">
                <el-input v-model="form.contacts" placeholder="请输入联系人" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="联系电话" prop="telephone">
                <el-input
                  v-model="form.telephone"
                  placeholder="请输入联系电话"
                  show-word-limit
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="联系人职务" prop="position">
                <el-input
                  v-model="form.position"
                  placeholder="请输入联系人职务"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="状态" prop="status">
                <el-select
                  v-model="form.status"
                  style="width: 100%"
                  placeholder="请选择状态"
                >
                  <el-option
                    v-for="dict in dict.type.enterprise_status"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="平台类别" prop="supplierType">
                <el-select
                  v-model="form.supplierType"
                  style="width: 100%"
                  placeholder="请选择机构类别"
                >
                  <el-option
                    v-for="dict in dict.type.customer_industry_garden"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="运营公司" prop="operationCompany" >
                <el-input v-model="form.operationCompany" placeholder="请选择企业名称" @focus="enterprise"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row style="margin: 0px -120px 12px 40px">
            <el-row :gutter="10" class="mb8">
              <el-col>
                <span
                  style="font-size: 14px; margin-left: 540px; margin-right: 5px"
                  >银行账号信息</span
                >
                <el-button
                  type="primary"
                  plain
                  icon="el-icon-plus"
                  size="mini"
                  @click="addBankListInfo"
                  style="text-align: center"
                ></el-button>
              </el-col>
            </el-row>
            <el-table :data="tableData" style="width: 91%">
              <el-table-column
                label="序号"
                type="index"
                align="center"
                prop="indexTwo"
              />
              <el-table-column
                prop="bank"
                label="银行名称"
                min-width="120"
                align="center"
              >
                <template slot-scope="scope">
                  <el-input v-model="scope.row.bank" />
                </template>
              </el-table-column>
              <el-table-column
                prop="accountNumber"
                label="账号"
                min-width="60"
                align="center"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.accountNumber"
                    maxlength="8"
                  />
                </template>
              </el-table-column>
              <el-table-column
                fixed="right"
                label="操作"
                min-width="40"
                align="center"
              >
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="small"
                    @click="delBankListInfo(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="经营范围" prop="businessScope">
                <el-input
                  v-model="form.businessScope"
                  placeholder="请输入经营范围"
                  type="textarea"
                  :autosize="{ minRows: 3, maxRows: 4 }"
                  maxlength="1000"
                  show-word-limit
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="创建人" prop="creationName">
                <el-input
                  v-model="form.creationName"
                  placeholder="请输入创建人"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 55px">
              <el-form-item label="创建时间" prop="creationTime">
                <el-input v-model="form.creationTime" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 70px">
              <el-form-item label="营业执照">
                <file-view
                  :type="fileType"
                  :businessId="businessId"
                  :businessCode="businessCode"
                  @change="getFile"
                  :key="refreshKey"
                ></file-view>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div style="text-align: center; margin-top: 30px">
          <el-button type="primary" @click="submitForm">保 存</el-button>
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane label="跟进记录" name="four" :disabled="isShowTab">
        <div style="text-align: center">
          <SupplierRecords
            :bId="bId"
            :enterpriseId="form.enterpriseId"
            :enterpriseName="form.enterpriseName"
            :contacts="form.contacts"
            :telephone="form.telephone"
          ></SupplierRecords>
        </div>
        <div style="text-align: center">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="荣誉资质信息"
        name="second"
        :disabled="isShowTab"
        v-if="isShowTabPane"
      >
        <Honor ref="honor" @change="loadList" :supplierId="supplierId"></Honor>
        <div style="text-align: center">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="有效商机信息"
        name="businessinfo"
        :disabled="isShowTab"
      >
        <Businessinfo
          ref="businessinfo"
          @change="loadList"
          :enterpriseId="form.enterpriseId"
          :enterpriseName="form.enterpriseName"
          :isEnterprise="isEnterprise"
          :isShowOpt="isShowOpt"
        >
        </Businessinfo>
        <div style="text-align: center">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <!-- <el-tab-pane label="合同信息" name="contract" :disabled="isShowTab">
                <Contract ref="contract" @change="loadList" :enterpriseId="form.enterpriseId"
                    :enterpriseName="form.enterpriseName">
                </Contract>
                <div style="text-align: center;">
                    <el-button type="primary" @click="cancel">关 闭</el-button>
                </div>
            </el-tab-pane> -->
      <el-tab-pane label="人员信息" name="person" :disabled="isShowTab">
        <Person
          ref="person"
          :bId="bId"
          :enterpriseId="form.enterpriseId"
          :isEnter="true"
          :enterpriseName="form.enterpriseName"
          @change="loadList"
          :showBtn="showBtn"
        >
        </Person>
        <div style="text-align: center">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane label="客户信息" name="enterprise" :disabled="isShowTab">
        <enterprise-list
          ref="enterprise"
          :platformName="form.enterpriseName"
          v-if="form.enterpriseName"
        >
        </enterprise-list>
        <div style="text-align: center">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane label="机构信息" name="organization" :disabled="isShowTab">
      <organization ref="organization" :dept-id="form.enterpriseOrgId">

      </organization>
      </el-tab-pane>
<!--      <el-tab-pane-->
<!--        label="活动培训"-->
<!--        name="activity"-->
<!--        :disabled="isShowTab"-->
<!--        v-if="isShowTabPane"-->
<!--      >-->
<!--        <Activity-->
<!--          ref="activity"-->
<!--          @change="loadList"-->
<!--          :enterpriseId="form.enterpriseId"-->
<!--          :enterpriseName="form.enterpriseName"-->
<!--          :initiationId="initiationId"-->
<!--          :receiverId="receiverId"-->
<!--          :bId="bId"-->
<!--        >-->
<!--        </Activity>-->
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane-->
<!--        label="问卷调查"-->
<!--        name="questionnaire"-->
<!--        :disabled="isShowTab"-->
<!--        v-if="isShowTabPane"-->
<!--      >-->
<!--        <Questionnaire-->
<!--          ref="questionnaire"-->
<!--          @change="loadList"-->
<!--          :initiationId="initiationId"-->
<!--          :receiverId="receiverId"-->
<!--        >-->
<!--        </Questionnaire>-->
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane-->
<!--        label="产品信息"-->
<!--        name="product"-->
<!--        :disabled="isShowTab"-->
<!--        v-if="isShowTabPane"-->
<!--      >-->
<!--        <Qualification-->
<!--          ref="product"-->
<!--          @change="loadList"-->
<!--          :supplierId="supplierId"-->
<!--        >-->
<!--        </Qualification>-->
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
<!--      </el-tab-pane>-->
    </el-tabs>
    <el-dialog title="选择机构" :visible.sync="openUser" width="800px" append-to-body>
      <change-enter v-if="openUser" @select-enterprise="handleSelectEnterprise">
      </change-enter>
    </el-dialog>
  </div>
</template>
<script>
import {
  getSupplierInfo,
  addInfo,
  updateInfo,
  getEnterpriseName,
  saveSupplierBank,
  updateSupplierBank,
} from "@/api/supplier/supplier";
import { listBank } from "@/api/bank/bank";
import FileView from "@/components/FileView/index";
import { listType } from "@/api/maintype/type";
//问卷调查
import Questionnaire from "./questionnaire";
//活动培训
import Activity from "./activity.vue";
import SupplierRecords from "./records.vue";
//商机信息
import Businessinfo from "../enterprise/businessinfo/index.vue";
//人员信息
import Person from "../enterprise/person/index.vue";
//荣誉资质
import Honor from "./honor.vue";
//合同信息
import Contract from "../contract/index.vue";
//产品信息
import Qualification from "./qualification";
import TreeSelect from "@riophae/vue-treeselect";
import { listArea } from "@/api/area/area";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getIndustryTree} from "@/api/enterprise/industry";
import ChangeEnter from "./institution.vue";
import EnterpriseList from "./enterprise.vue";
import Organization from "./organization.vue";
export default {
  name: "Info",
  dicts: [
    "sys_org_type",
    "tracking_stage",
    "supplier_type",
    "customer_industry_serve",
    "customer_industry_garden",
    "enterprise_nature",
    "customer_industry",
    "enterprise_records",
    "enterprise_status",
    "enterprise_source",
    "tracking_stage",
    "enterprise_records",
  ],
  components: {
    Organization,
    EnterpriseList,
    ChangeEnter,
    Questionnaire,
    Activity,
    TreeSelect,
    Contract,
    FileView,
    Honor,
    Businessinfo,
    SupplierRecords,
    Person,
    Qualification,
  },
  props: {
    opt: {
      type: String,
      default: "",
    },

    id: {
      type: String,
      default: "",
    },
    //序号
    index: {
      type: String,
      default: 0,
    },
    classId: {
      type: Number,
      default: 0,
    },
    supplierId: {
      type: Number,
      default: 0,
    },
    receiverId: {
      type: Number,
      default: 0,
    },
    enterpriseNo: {
      type: Number,
      default: 0,
    },
    initiationId: {
      type: Number,
      default: 0,
    },
    tabId: {
      type: Number,
      default: null,
    },
  },
  data() {
    return {
      industryOptions: [], // 行业树形数据
      tableData: [],
      showBtn: false,
      bId: "",
      industryType: "2",
      isShowAdd: true,
      isCertified: false,
      isEnterprise: true,
      isShowOpt: false,
      lable: null,
      saleId: null,
      refreshKey: 0,
      readonly: true,
      opt1: false,
      platformName:null,//园区名称
      opt2: false,
      opt3: false,
      checkCount: 0,
      isShowTab: true,
      isShowTabSJ: true,
      UUID: "",
      userType: "1",
      optionData: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      queryHighSeas: {
        pageNum: 1,
        pageSize: 15,
        enterpriseId: null,
        administrativeArea: null,
        enterpriseNature: null,
        industry: null,
        classificationId: null,
      },
      queryRecordParams: {
        pageNum: 1,
        pageSize: 15,
        businessId: null,
        followTime: null,
        followId: null,
        followPerson: null,
        followStage: null,
        type: null,
        latestDevelopments: null,
        annotationsId: null,
        annotationsName: null,
        annotations: null,
      },
      // 非单个禁用
      single: true,
      openUser: false,
      orgId: 100,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //行政区域
      options: null,
      // 平台信息表格数据
      recordsList: [],
      businessCode: "business_license", //营业执照
      enterpriseinfo: "enterpriseinfo",
      // 弹出层标题
      title: "",
      sign: "1",
      honorShow: "0",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        industryType: "0",
        enterpriseId: null,
      },
      // 表单参数
      form: {
        industryType: "2",
        creationName: this.$store.state.user.name,
        creationTime: this.parseTime(new Date(), "{y}-{m}-{d}"),
      },
      // 表单校验
      // 表单校验
      rules: {
        registeredCapital: [
          { max: 50, message: "注册资金长度不能超过50", trigger: "blur" },
        ],
        legalRepresentative: [
          { max: 50, message: "法人代表长度不能超过50", trigger: "blur" },
        ],
        enterpriseName: [
          { required: true, message: "平台名称不能为空", trigger: "blur" },
          { max: 50, message: "平台名称长度不能超过50", trigger: "blur" },
        ],
        enterpriseAddress: [
          { required: true, message: "详细地址不能为空", trigger: "blur" },
          { max: 499, message: "详细地址长度不能超过500字", trigger: "blur" },
        ],
        administrativeArea: [
          { required: true, message: "行政区域不能为空", trigger: "change" },
        ],
        enterpriseNature: [
          { required: true, message: "平台性质不能为空", trigger: "change" },
        ],
        enterpriseSource: [
          { required: true, message: "平台来源不能为空", trigger: "change" },
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "change" },
        ],
        position: [
          { max: 30, message: "联系人职务长度不能超过30字", trigger: "blur" }
        ],
        contacts: [
          { required: true, message: "联系人姓名不能为空", trigger: "blur" },
          { max: 36, message: "联系人姓名长度不能超过36", trigger: "blur" },
        ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
          { max: 50, message: "联系电话长度不能超过50", trigger: "blur" },
        ],
        industry: [
          { required: true, message: "所属行业不能为空", trigger: "change" },
        ],
      },
      queryParamsElectric: {
        pageNum: 1,
        pageSize: 15,
        enterpriseName: null,
        enterpriseAddress: null,
        enterpriseNature: null,
        electricType: null,
        classificationId: null,
      },
      //复选框
      markAs: null,
      //选显卡默认选中
      activeName: "first",
      isShowTabPane: false,
      //
      show: "",
      //上传按钮隐藏
      isShow: true,
      url: "",

      fileType: 0,
      businessId: null,
      zValue: 0,
    };
  },
  created() {
    if (this.tabId != "" && this.tabId != null) {
      this.isShowTabPane = true;
    }
    if (this.$store.state.user.info.companyType != "0") {
      this.isCertified = true;
    }
    if (this.opt == "add") {
      this.fileType = 0;
      this.isShowTabPane = false;
      this.businessId = this.id;
      this.enterpriseId = this.id;
      this.bId = this.id;
      this.form.type = "2";
      if (this.enterpriseNo == 0) {
        this.form.enterpriseNo = "PT0001";
      } else {
        if (this.enterpriseNo < 10) {
          this.form.enterpriseNo = "PT000" + parseInt(this.enterpriseNo + 1);
        }
        if (this.enterpriseNo >= 10 && this.enterpriseNo <= 99) {
          this.form.enterpriseNo = "PT00" + parseInt(this.enterpriseNo + 1);
        }
        if (this.enterpriseNo >= 100 && this.enterpriseNo <= 999) {
          this.form.enterpriseNo = "PT0" + parseInt(this.enterpriseNo + 1);
        }
        if (this.enterpriseNo >= 1000) {
          this.form.enterpriseNo = "PT" + parseInt(this.enterpriseNo + 1);
        }
      }
    }
    if (this.opt == "edit") {
      this.isShowTab = false;
      this.fileType = 1;
      this.bId = this.id;
      this.refreshKey++;
      this.handleUpdate(this.id);
    }
    if (this.opt == "details") {
      this.refreshKey++;
      this.isShowTab = false;
      this.fileType = 2;
      this.bId = this.id;
      this.handleUpdate(this.id);
    }
    this.area();
    this.getIndustryTree();
  },
  methods: {
    getIndustryTree() {
      getIndustryTree().then(response => {
        if (response.code === 200) {
          this.industryOptions = response.data;
        } else {
          this.$modal.msgError(response.msg);
        }
      }).catch(error => {
        this.$modal.msgError('获取行业数据失败');
      });
    },
    enterprise() {
      this.openUser = true;
    },
    handleSelectEnterprise(data) {
      // 处理企业选择
      console.log(data)
      this.form.operationCompany = data.enterpriseName;
      this.form.operationCompanyId = data.enterpriseId;
      this.openUser = false;
    },
    industryNormalizer(node) {
      return {
        id: node.industryId,
        label: node.name,
        children: node.children && node.children.length > 0 ? node.children : null
      };
    },

    // 处理行业选择变化
    handleIndustryChange(value) {
      if (value) {
        // 根据选择的行业ID更新industryType
        const findIndustryType = (options, targetId) => {
          for (const option of options) {
            if (option.industryId === targetId) {
              // 根据行业的层级设置industryType
              this.form.industryType =
                option.levelType === 1
                  ? "0"
                  : option.levelType === 2
                    ? "1"
                    : "2";
              return true;
            }
            if (option.children) {
              if (findIndustryType(option.children, targetId)) {
                return true;
              }
            }
          }
          return false;
        };
        findIndustryType(this.industryOptions, value);
      }
    },

    loadOptions({ action, parentNode, callback }) {
      callback(null, []);
    },

    delBankListInfo(row) {
      this.tableData = this.tableData.filter(
        data => data.paymentId !== row.paymentId
      );
    },

    // 添加加载行业选项的方法
    loadIndustryOptions({ action, parentNode, callback }) {
      if (action === "LOAD_CHILDREN_OPTIONS") {
        // 如果需要异步加载子节点，在这里调用API
        getIndustryTree({ parentId: parentNode.industryId })
          .then(response => {
            if (response.code === 200) {
              const children = response.data.map(item => ({
                id: item.industryId,
                label: item.name,
                children: item.children && item.children.length > 0 ? [] : null,
              }));
              callback(null, children);
            }
          })
          .catch(err => {
            callback(err);
          });
      }
    },

    addBankListInfo() {
      var tableList = this.tableData;
      var num = 0;
      for (var i = 0; i < tableList.length; i++) {
        if (
          tableList[i].bank == "" ||
          tableList[i].bank == null ||
          tableList[i].accountNumber == "" ||
          tableList[i].accountNumber == null
        ) {
          num++;
        }
      }
      if (num > 0) {
        this.$message.error("请先填写好银行账号信息！");
      } else {
        this.tableData.push({
          indexTwo: tableList.length + 1,
          id: this.guId(),
          enterpriseId: this.bId,
          bank: "",
          accountNumber: "",
        });
      }
    },
    areaChange(val) {
      this.$nextTick(() => {
        this.$refs.form.validateField("administrativeArea");
      });
    },

    handleRadioChange(value) {
      this.industryType = value;
      if (value == 0) {
        this.dict.type.customer_industry.forEach(item => {
          if (
            item.value != this.form.industry &&
            this.form.industry != "undifend" &&
            this.form.industry != null &&
            this.form.industry != ""
          )
            this.form.industry = "";
        });
      }
      if (value == 1) {
        this.dict.type.customer_industry_serve.forEach(item => {
          if (
            item.value != this.form.industry &&
            this.form.industry != "undifend" &&
            this.form.industry != null &&
            this.form.industry != ""
          )
            this.form.industry = "";
        });
      }
      if (value == 2) {
        this.dict.type.customer_industry_garden.forEach(item => {
          if (
            item.value != this.form.industry &&
            this.form.industry != "undifend" &&
            this.form.industry != null &&
            this.form.industry != ""
          )
            this.form.industry = "";
        });
      }
    },
    validateEnterpriseName() {
      if (this.form.enterpriseName != null && this.form.enterpriseName != "") {
        getEnterpriseName(this.form.enterpriseName).then(response => {
          if (
            response != "" &&
            response != null &&
            response.enterpriseId != this.form.enterpriseId
          ) {
            this.$message.error("该平台名称在供应商或平台关系中已存在！");
          }
        });
      }
    },
    area() {
      listArea()
        .then(response => {
          if (response.code === 200) {
            this.options = this.formatAreaData(response.data);
          } else {
            this.$modal.msgError("获取行政区域失败");
          }
        })
        .catch(error => {
          console.error("加载行政区域失败:", error);
          this.$modal.msgError("加载行政区域失败");
        });
    },

    formatAreaData(data) {
      return data.map(item => ({
        id: item.areaId,
        label: item.areaName,
        children:
          item.list && item.list.length > 0
            ? this.formatAreaData(item.list)
            : null,
      }));
    },

    normalizer(node) {
      return {
        id: node.id,
        label: node.label,
        children: node.children,
      };
    },
    loadList() {
      this.$emit("change", this.zValue);
    },
    getFile(data) {
      //console.log(JSON.stringify(data))
    },
    // 取消按钮
    cancel() {
      this.reset();
      this.$emit("change");
    },
    //获取树节点数据
    listType() {
      listType({ typeCode: "enterprise" }).then(res => {
        this.optionData = res.data;
      });
    },

    close(data) {
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(id) {
      this.reset();
      this.form.creationName = this.$store.state.user.name;
      this.form.creationTime = this.parseTime(new Date(), "{y}-{m}-{d}");
      getSupplierInfo(id).then(response => {
        console.log(response);
        this.form = response.data;
        this.platformName=response.data.enterpriseName;
        this.industryType = response.data.industryType;
        if (
          this.form.enterpriseOrgId == "" ||
          this.form.enterpriseOrgId == null
        ) {
          this.businessId = response.data.enterpriseId;
        } else {
          this.businessId = response.data.enterpriseOrgId;
        }
        if (this.form.enterpriseNo < 10) {
          this.form.enterpriseNo = "PT000" + this.form.enterpriseNo;
        }
        if (this.form.enterpriseNo >= 10 && this.form.enterpriseNo <= 99) {
          this.form.enterpriseNo = "PT00" + this.form.enterpriseNo;
        }
        if (this.form.enterpriseNo >= 100 && this.form.enterpriseNo <= 999) {
          this.form.enterpriseNo = "PT0" + this.form.enterpriseNo;
        }
        if (this.form.enterpriseNo >= 1000) {
          this.form.enterpriseNo = "PT" + this.form.enterpriseNo;
        }
        this.refreshKey++;
      });
       const bankList = {
        enterpriseId: id,
      };
      listBank(bankList).then(response => {
        this.tableData = response.rows;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        areaName: null,
        enterpriseId: null,
        enterpriseOrgId: null,
        classificationId: null,
        classificationName: null,
        enterpriseName: null,
        administrativeArea: null,
        markAs: null,
        markAsName: null,
        position:null,
        enterpriseNature: null,
        enterpriseNo: null,
        enterpriseSource: null,
        enterpriseAbbreviation: null,
        legalRepresentative: null,
        establishmentDate: null,
        enterpriseLabel: null,
        registeredCapital: null,
        contractAmount: null,
        industry: null,
        contacts: null,
        telephone: null,
        bankName: null,
        bankNo: null,
        idPath: null,
        taxId: null,
        transactionId: null,
        businessManager: null,
        developmentId: null,
        developmentManager: null,
        status: null,
        enterpriseAddress: null,
        businessScope: null,
        belongTo: null,
        creationTime: null,
        creationId: null,
        creationName: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        delFlag: null,
        operationCompany:null,
        operationCompanyId:null,
      };
      this.resetForm("form");
    },
    handleClick(tab, event) {
      //问卷调查
      if (tab.name == "questionnaire") {
        this.$nextTick(() => {
          this.$refs.questionnaire.getList();
        });
      }
      //活动培训
      if (tab.name == "activity") {
        this.$nextTick(() => {
          this.$refs.activity.getList();
        });
      }
      //荣誉资质
      if (tab.name == "second") {
        this.$nextTick(() => {
          this.$refs.honor.getList();
        });
      }
      if (tab.name == "businessinfo") {
        this.$nextTick(() => {
          //商机管理

          this.$refs["businessinfo"].getList();
        });
      }

      if (tab.name == "contract") {
        //合同
        this.$nextTick(() => {
          //合同管理
          this.$refs["contract"].getList();
        });
      }

      if (tab.name == "person") {
        this.$nextTick(() => {
          //人员管理
          this.$refs["person"].getList();
        });
      }
      if (tab.name == "enterprise") {
        this.$nextTick(() => {
          if(this.form.enterpriseName) {
            this.$refs["enterprise"].getList();
          }
        });
      }
      if (tab.name=="organization"){
        this.$nextTick(() => {
          if(this.form.enterpriseOrgId) {
            this.$refs["organization"].getList();
          }
        });
      }
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          getEnterpriseName(this.form.enterpriseName).then(response => {
            if (
              response != "" &&
              response != null &&
              response.enterpriseId != this.form.enterpriseId
            ) {
              this.$message.error("该平台名称在供应商或平台关系中已存在！");
            } else {
              if (this.form.enterpriseId != null) {
                this.form["supplierBankList"] = this.tableData;
                const data = this.form;
                updateSupplierBank(data).then(response => {
                  this.$modal.msgSuccess("修改成功");
                });
              } else {
                this.form.enterpriseId = this.id;
                this.form["supplierBankList"] = this.tableData;
                const data = this.form;
                saveSupplierBank(data).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.isShowTab = false;
                });
              }
            }
          });
        }
      });
    },
    guId() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (
        S4() +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        S4() +
        S4()
      );
    },
  },
};
</script>
<style scoped lang="scss">
.teacher-form-container {
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px;
  max-width: 100%;
  max-height: 80vh;
  box-sizing: border-box;
}
</style>
